package com.txm.model.hibernate;

import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Set;

/**
 * Created by Administrator on 2016/4/21.
 */
@Entity
@XmlRootElement//mvc绑定xml数据
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "all")
public class User implements Serializable {
    @Id
    @GeneratedValue
    private Integer id;

    /*一对一单向关联*/

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "iDCardId", unique = true)
    private IDCard idCard;

    @ManyToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JoinColumn(name = "classRoomId")
    private ClassRoom classRoom;//班级信息
    @ManyToMany
    @JoinTable(
            name = "teacher_student", joinColumns = {@JoinColumn(name = "sid")}, inverseJoinColumns = {@JoinColumn(name = "tid")}
    )
    private Set<Teacher> teacherSet;

    public Set<Teacher> getTeacherSet() {
        return teacherSet;
    }

    public void setTeacherSet(Set<Teacher> teacherSet) {
        this.teacherSet = teacherSet;
    }

    public ClassRoom getClassRoom() {
        return classRoom;
    }

    public void setClassRoom(ClassRoom classRoom) {
        this.classRoom = classRoom;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public IDCard getIdCard() {
        return idCard;
    }

    @XmlElement(name = "idCard")
    public void setIdCard(IDCard idCard) {
        this.idCard = idCard;
    }
}
